<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>SC2API: include/sc2api/sc2_connection.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="SC2-Logo.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">SC2API
   </div>
   <div id="projectbrief">An API for AI for StarCraft II</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_3d0dfd3160b31ffa512c49330ac8d646.html">sc2api</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">sc2_connection.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="sc2__connection_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;</div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="preprocessor">#pragma once</span></div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;</div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="preprocessor">#include &lt;string&gt;</span></div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#include &lt;mutex&gt;</span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#include &lt;condition_variable&gt;</span></div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="preprocessor">#include &lt;deque&gt;</span></div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor">#include &lt;functional&gt;</span></div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="preprocessor">#include &lt;atomic&gt;</span></div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;</div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="keyword">struct </span>mg_connection;</div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;</div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespace_s_c2_a_p_i_protocol.html">SC2APIProtocol</a> {</div><div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;    <span class="keyword">class </span>Request;</div><div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;    <span class="keyword">class </span>Response;</div><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;}</div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;</div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespacesc2.html">sc2</a> {</div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;</div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;</div><div class="line"><a name="l00026"></a><span class="lineno"><a class="line" href="classsc2_1_1_connection.html">   26</a></span>&#160;<span class="keyword">class </span><a class="code" href="classsc2_1_1_connection.html">Connection</a> {</div><div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="keyword">public</span>:</div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;    <a class="code" href="classsc2_1_1_connection.html">Connection</a>();</div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;    ~<a class="code" href="classsc2_1_1_connection.html">Connection</a>();</div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;</div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;    <span class="keywordtype">bool</span> Connect(<span class="keyword">const</span> std::string&amp; address, <span class="keywordtype">int</span> port, <span class="keywordtype">bool</span> verbose = <span class="keyword">true</span>);</div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;</div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;    <span class="keywordtype">void</span> Send(<span class="keyword">const</span> SC2APIProtocol::Request* request);</div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;</div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;    <span class="keywordtype">bool</span> Receive(SC2APIProtocol::Response*&amp; response, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> timeout_ms);</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;</div><div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;    <span class="keywordtype">void</span> PopResponse(SC2APIProtocol::Response*&amp; response);</div><div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;    <span class="keywordtype">void</span> SetTimeoutCallback(std::function&lt;<span class="keywordtype">void</span>()&gt; callback);</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;</div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;    <span class="keywordtype">void</span> SetConnectionClosedCallback(std::function&lt;<span class="keywordtype">void</span>()&gt; callback);</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;    <span class="keywordtype">bool</span> HasConnection() <span class="keyword">const</span>;</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;    <span class="keywordtype">bool</span> PollResponse();</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;    <span class="keywordtype">void</span> PushResponse(SC2APIProtocol::Response*&amp; response);</div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;</div><div class="line"><a name="l00077"></a><span class="lineno"><a class="line" href="classsc2_1_1_connection.html#abab9f14cde0fe589fc3a1c9588c6607a">   77</a></span>&#160;    std::function&lt;void()&gt; <a class="code" href="classsc2_1_1_connection.html#abab9f14cde0fe589fc3a1c9588c6607a">timeout_callback_</a>;             </div><div class="line"><a name="l00078"></a><span class="lineno"><a class="line" href="classsc2_1_1_connection.html#a4df89365bfaec33df14cf9a84f42c938">   78</a></span>&#160;    std::function&lt;void()&gt; <a class="code" href="classsc2_1_1_connection.html#a4df89365bfaec33df14cf9a84f42c938">connection_closed_callback_</a>;   </div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;</div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;<span class="keyword">private</span>:</div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;    <span class="keywordtype">bool</span> verbose_;                                   </div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;    mg_connection* connection_;                      </div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;    std::deque&lt;SC2APIProtocol::Response*&gt; queue_; </div><div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;    std::mutex mutex_;                               </div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;    std::condition_variable condition_;              </div><div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;</div><div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;    std::atomic_bool has_response_;                  </div><div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;};</div><div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;</div><div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;}</div><div class="ttc" id="classsc2_1_1_connection_html"><div class="ttname"><a href="classsc2_1_1_connection.html">sc2::Connection</a></div><div class="ttdef"><b>Definition:</b> sc2_connection.h:26</div></div>
<div class="ttc" id="namespacesc2_html"><div class="ttname"><a href="namespacesc2.html">sc2</a></div><div class="ttdef"><b>Definition:</b> sc2_action.h:9</div></div>
<div class="ttc" id="classsc2_1_1_connection_html_a4df89365bfaec33df14cf9a84f42c938"><div class="ttname"><a href="classsc2_1_1_connection.html#a4df89365bfaec33df14cf9a84f42c938">sc2::Connection::connection_closed_callback_</a></div><div class="ttdeci">std::function&lt; void()&gt; connection_closed_callback_</div><div class="ttdoc">Timeout callback. </div><div class="ttdef"><b>Definition:</b> sc2_connection.h:78</div></div>
<div class="ttc" id="classsc2_1_1_connection_html_abab9f14cde0fe589fc3a1c9588c6607a"><div class="ttname"><a href="classsc2_1_1_connection.html#abab9f14cde0fe589fc3a1c9588c6607a">sc2::Connection::timeout_callback_</a></div><div class="ttdeci">std::function&lt; void()&gt; timeout_callback_</div><div class="ttdoc">Timeout callback. </div><div class="ttdef"><b>Definition:</b> sc2_connection.h:77</div></div>
<div class="ttc" id="namespace_s_c2_a_p_i_protocol_html"><div class="ttname"><a href="namespace_s_c2_a_p_i_protocol.html">SC2APIProtocol</a></div><div class="ttdef"><b>Definition:</b> sc2_connection.h:16</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
